/**
 * @properties={typeid:35,uuid:"20650D60-0B59-4E46-B504-132712BEBA3F",variableType:-4}
 */
var $NOMBRE_SERVIDOR = globals.$NOMBRE_SERVIDOR;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"175928EA-A19F-40F7-818B-B2D62FE9423B"}
 */
var $NOMBRE_TABLA = "adm_t900_menus";

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"4BD3C1C7-5ADE-4ABA-9D29-C3C284AEC99F"}
 */
var $DATA_SOURCE = "db:/" + $NOMBRE_SERVIDOR + "/" + $NOMBRE_TABLA;

/**
 * Inicializa los menús
 * @author Roberto J. Blasco
 * @version 1.0
 * @properties={typeid:24,uuid:"712C623C-5ABB-46B2-8298-B731FD629A6F"}
 */
function inicializar_menus(){
	
	/** @type {JSFoundSet<db:/pigeon_board/adm_t900_menus>} */
	var fs_adm_t900_menus = databaseManager.getFoundSet($DATA_SOURCE);
	fs_adm_t900_menus.loadAllRecords();
	
	if (fs_adm_t900_menus.getSize() == 0){
		fs_adm_t900_menus.newRecord();
		fs_adm_t900_menus.n_orden = 100;
		fs_adm_t900_menus.s_descripcion = "Inicio";
		fs_adm_t900_menus.s_icono = "media:///iconos/ic_home_white_18dp.png";
		databaseManager.saveData(fs_adm_t900_menus);
		var id_inicio = fs_adm_t900_menus.getRecord(1).adm_t900_menus_id;
		fs_adm_t900_menus.newRecord();
		fs_adm_t900_menus.n_orden = 101;
		fs_adm_t900_menus.adm_t900_menus_padre_id = id_inicio;
		fs_adm_t900_menus.s_descripcion = "Sobre";
		fs_adm_t900_menus.s_icono = "media:///iconos/ic_help_white_18dp.png";
		fs_adm_t900_menus.s_funcion = "sobre";
		fs_adm_t900_menus.newRecord();
		fs_adm_t900_menus.n_orden = 102;
		fs_adm_t900_menus.adm_t900_menus_padre_id = id_inicio;
		fs_adm_t900_menus.s_descripcion = "Salir";
		fs_adm_t900_menus.s_descripcion = "salir";
		fs_adm_t900_menus.s_icono = "media:///iconos/ic_settings_white_18dp.png";
		databaseManager.saveData(fs_adm_t900_menus);
		fs_adm_t900_menus.newRecord();
		fs_adm_t900_menus.n_orden = 200;
		fs_adm_t900_menus.s_descripcion = "Administración";
		fs_adm_t900_menus.s_icono = "media:///iconos/ic_settings_phone_white_18dp.png";
		databaseManager.saveData(fs_adm_t900_menus);
		var id_adm = fs_adm_t900_menus.getRecord(1).adm_t900_menus_id;
		fs_adm_t900_menus.newRecord();
		fs_adm_t900_menus.n_orden = 201;
		fs_adm_t900_menus.adm_t900_menus_padre_id = id_adm;
		fs_adm_t900_menus.s_descripcion = "Menús";
		fs_adm_t900_menus.s_icono = "media:///iconos/ic_dns_white_18dp.png";
		fs_adm_t900_menus.s_funcion = "adm_t900_menus";
		databaseManager.saveData(fs_adm_t900_menus);
	}
}

/**
 * Despliega el menú<br>
 * Si no se le pasa parámetro muestra sólo los menus iniciales
 * @author Roberto J. Blasco
 * @version 1.0
 * @param {JSRecord<db:/pigeon_board/adm_t900_menus>} [record_adm_t900_menus]
 * @return {JSFoundSet<db:/pigeon_board/adm_t900_menus>}
 *
 * @properties={typeid:24,uuid:"AAFAC546-6DE9-4141-9186-39518D0A979C"}
 * @AllowToRunInFind
 */
function mostrar_menu(record_adm_t900_menus){
	
	/** @type {JSFoundSet<db:/pigeon_board/adm_t900_menus>} */
	var fs_adm_t900_menus = databaseManager.getFoundSet(scopes.adm_t900_menus.$DATA_SOURCE)
	fs_adm_t900_menus.loadAllRecords();
	
	if (record_adm_t900_menus == null){
		if (fs_adm_t900_menus.find()){
			fs_adm_t900_menus.adm_t900_menus_padre_id = '^';
			fs_adm_t900_menus.search();
		}
		return fs_adm_t900_menus;
	}else{
		if (fs_adm_t900_menus.find()){
			fs_adm_t900_menus.adm_t900_menus_padre_id = '^';
			fs_adm_t900_menus.newRecord();
			fs_adm_t900_menus.adm_t900_menus_padre_id = record_adm_t900_menus.adm_t900_menus_id;
			fs_adm_t900_menus.search();
			fs_adm_t900_menus.sort("n_orden  asc")
		}
		return fs_adm_t900_menus;
	}
}

/**
 * @properties={typeid:24,uuid:"B26454BC-A2E0-49C3-812D-1D792EF1CC20"}
 */
function salir(){
	
	application.exit();
}

/**
 * @properties={typeid:24,uuid:"B4B1AC65-8AC3-44B7-A948-442F83325F65"}
 */
function sobre(){
	
	application.output(application.getSolutionName());
}

/**
 * @properties={typeid:24,uuid:"C9EE1D9B-3B7D-4A5B-B571-8196E961B4A4"}
 */
function adm_t900_menus(){
	
	forms[globals.$frm_siv_main].elements.tab_principal.removeAllTabs();
	forms[globals.$frm_siv_main].elements.tab_principal.addTab(forms.lst_adm_t900_menus);
}

/**
 * @properties={typeid:24,uuid:"337A68FB-E80A-4264-8DB3-D2A1DB119773"}
 */
function f_adm_empresas(){
	
	forms[globals.$frm_siv_main].elements.tab_principal.removeAllTabs();
	forms[globals.$frm_siv_main].elements.tab_principal.addTab(forms.lst_adm_t900_empresas);
}

/**
 * @properties={typeid:24,uuid:"85D76C8C-F2F8-4135-946C-A10E118890DA"}
 */
function f_adm_perfiles(){
	
	forms[globals.$frm_siv_main].elements.tab_principal.removeAllTabs();
	forms[globals.$frm_siv_main].elements.tab_principal.addTab(forms.lst_adm_t900_perfiles);
}

/**
 * @properties={typeid:24,uuid:"87D2E773-B23A-45ED-823E-91E1ACDC3568"}
 */
function f_adm_usuarios(){
	
	forms[globals.$frm_siv_main].elements.tab_principal.removeAllTabs();
	forms[globals.$frm_siv_main].elements.tab_principal.addTab(forms.lst_adm_t900_usuarios);
}

/**
 * @properties={typeid:24,uuid:"6387BC56-79D7-4E93-928F-FAEA6C406687"}
 */
function f_adm_roles(){
	
	forms[globals.$frm_siv_main].elements.tab_principal.removeAllTabs();
	forms[globals.$frm_siv_main].elements.tab_principal.addTab(forms.lst_adm_t900_roles);
}

/**
 * @properties={typeid:24,uuid:"9AE9B936-9099-43B3-B3A7-4427FD221646"}
 */
function f_adm_tablas(){
	
	forms[globals.$frm_siv_main].elements.tab_principal.removeAllTabs();
	forms[globals.$frm_siv_main].elements.tab_principal.addTab(forms.lst_adm_t900_tablas);
}
